﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Vara_Data_Layer.Vara_Data_Holder
{
    public class Vara_Data_Holder_Controller : Vara_Data_IHolder_Actions
    {
        public Vara_Data_IHolder ReturnHolder(int ID)
        {
            Vara_Data_IHolder HolderToReturn = new Vara_Data_Holder(ID);
            DataRow DataRowHolderInformation;
            using (SqlEngine NewSqlConnector = new SqlEngine("AssetTracking"))
            {
                DataRowHolderInformation = NewSqlConnector.ExecuteProcedure("Return_Holder",
                                                new SqlEngineProcedureVariable("@HolderID", ID, SqlDbType.Int)).Rows[0];
            }
            HolderToReturn.FirstName = DataRowHolderInformation["FirstName"].ToString();
            HolderToReturn.LastName = DataRowHolderInformation["LastName"].ToString();
            HolderToReturn.PersonReference = DataRowHolderInformation["PersonReference"].ToString();
            switch (DataRowHolderInformation["PersonType"].ToString())
            {
                case "Staff":
                    HolderToReturn.Type = PersonType.Staff;
                    break;
                case "Student":
                    HolderToReturn.Type = PersonType.Student;
                    break;
                case "External":
                    HolderToReturn.Type = PersonType.External;
                    break;
            }

            return HolderToReturn;
        }
    }
}
